Q: Is CSS used with VB programming? Or just with browsers?
A: CSS works with browsers. Compared to CSS, VB programming allows you much greater control over how you format your data and your UI. This is because you design and build VB programs from the ground up.
Displaying XML in a browser is different than displaying it in your own programs like the cookbook project. Chapters 2 and 3 in this lesson are all about using CSS to format data so it looks the way you want it to in a browser. But you don't use CSS with ordinary VB programs.
Remember that you can't modify a browser. A team at Microsoft wrote the IE browser program, and a team at Google wrote Chrome. And in each case, when they finished writing their browser, they closed its doors and sealed it off. You get to use their browser, but they don't give you the browser's code so that you can modify it.
The most you can do to influence how browsers format data is to write style rules using a language like CSS. You filter your raw XML through a CSS style sheet, causing the browser to ignore its default presentation rules and show the contents according to your rules. But you're not changing the browser's actual code.
By contrast, when you write your own programs, you're in complete control. Instead of writing CSS rules, you add VB controls like listboxes and textboxes to your program. And you can easily modify your program's presentation and behavior in several powerful ways:
Use the editor's Design window to create a custom UI.
Use the Properties window to control how forms and controls look and act.
Write code to specify what your program does and how it does it.
Q: What does cascading mean in Cascading Style Sheets?
A: I was afraid some sharp student would ask this. For
simple tasks like displaying your cookbook in a browser, the semi-advanced
cascade technique doesn't matter. But if you're curious, cascading handles conflicting
style rules. For example, say that a style sheet specifies that a title element's
text should be blue, but elsewhere another style rule says that titles should
be black. Which color should be displayed in the browser?
The cascade
is a set of rules determining which style takes precedence when CSS
style rules disagree. But how can this disagreement even happen? You're only
supplying that one .css file and it says for example blue! Large websites might employ more than one .CSS file, or
sometimes HTML documents contain CSS code right in with the HTML code, in
addition to the code in a separate CSS file. Or users might write their own
custom style sheets because they prefer a particular typeface, for example. The
users want to override your CSS typeface specification (user style rules take
precedence over all others). In other words, a browser might have to interpret
multiple style rules from different sources, some of them contradictory. The
cascade tells the browser how to sort out this conflict—which of multiple CSS
specifications should be used.
For today's assignment, practice working with a few CSS style rules. Your task is to edit the Cookbook CSS Stylesheet.css file that you created in this lesson so it displays the recipes according to these style rules:
- Indent the instructions 5% and the titles 2% from the right and left sides of the browser window.
- Give the instructions a bottom margin of 4%.
- Display the titles and instructions in a sans-serif typeface.
- Display the titles in the FireBrick color.